$('#stock_pool_search').linkbutton({  //查询按钮
    iconCls: "icon-search"
});

function removeStockPool() {
    var checkedItems = $('#stock_pool_table').datagrid('getChecked');
    if (listIsEmpty(checkedItems)) {
        $.messager.alert("操作提示", "请选中股票后操作！", "warning");
        return;
    }
    var names = [];
    $.each(checkedItems, function (index, item) {
        names.push(item.id);
    });
    $.ajax({
        /*type = "get",*/
        url: '/pool/remove-pool-batch',
        dateType: "JSON",
        data: {"ids": names.join(',')},
        success: function (data, textStatus, jqXHR) {
            poo_info.search();
        }
    });
}

var pool_info = {                     //obj对象
    search: function () {
        $('#stock_pool_table').datagrid('load', $("#stock_pool_form").parseForm());
    }
};
$(function () {


    $('#stock_pool_search').click(function () {
        pool_info.search()
    });


    $('#stock_pool_table').datagrid({
        // width: 1500,                 //设置宽度
        url: '/pool/query-all',       //远程加载数据地址
        title: '股票池',           //面板属性，添加标题
        iconCls: 'icon-search',     //添加图标
        method: 'get',
        queryParams: $("#stock_pool_form").parseForm(),
        selectOnCheck: true,
        remoteSort: true,
        columns: [[
            {
                field: 'id',
                // title: '股票名称',
                checkbox: true,
                width: 60
            },
            {
                field: 'stock_name',
                title: '股票名称',
                formatter: linkStockDetail
            },
            {
                field: 'industry_name',
                title: '行业名称'
            }
            , {
                field: 'now_price',
                title: '当前价'
            }
            , {
                field: 'volume_ratio',
                title: '量比'
            }
            , {
                field: 'pctChg',
                title: '涨跌幅'
            }
            , {
                field: 'turn',
                title: '换手率'
            }

            , {
                field: 'create_time',
                title: '创建时间',
                formatter: dateFormatter
            }
            , {
                title: '操作',
                resizable: true,
                field: '获取最新',
                formatter: formatOper
            }

        ]],
        pagination: true,         //组件底部显示分页工具栏
        pageNumber: 1,             //设置分页时初始化页码
        pageSize: 20,               //设置分页时设置每页多少条
        pageList: [20, 50, 100, 500],          //设置可选每页显示条数
        fitColumns: true,         //设置表格自适应
        // {#scrollbarSize: 0,          //滚动条所占的宽度或高度。默认为18。#}
        rownumbers: true,
        onBeforeLoad: function (param) {
            var firstLoad = $(this).attr("firstLoad");
            if (firstLoad == "false" || typeof (firstLoad) == "undefined") {
                $(this).attr("firstLoad", "true");
                return false;
            }
            return true;
        },
        toolbar: '#stock_pool_toolbar'
    });


});

function formatOper(val, row, index) {
    if (row.optional_state == 0) {
        return ' <button class="easyui-linkbutton" onclick="addOptional(\'' + row.id + '\')">加入自选</button> ';
    } else {
        return '';
    }
}

function addOptional(id) {
      $.ajax({
        /*type = "get",*/
        url: '/optional/pool/add',
        dateType: "JSON",
        data: {"id": id},
        success: function (data, textStatus, jqXHR) {
            pool_info.search()
        }
    });

}

